<?php
/*
	
*/
defined('BY_JYA') or exit('Access Denied');
global $_RQ,$_AR;

$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
$setting=$this->plugin_setting('setting');
$return['banner']=$setting['hdps'];
if($_RQ['op']=='list'){
	$params=array('uniacid'=>$_SESSION['uniacid'],'status'=>'1');

	//状态为显示的所有活动，排序
	$list=pdo_getall('jy_cmsactivity_list',$params,'','','paixu asc');
	foreach($list as &$item){
		$num1=pdo_count('jy_cmsactivity_order',array('uniacid'=>$_SESSION['uniacid'],'activity_id'=>$item['id'],'status'=>1));
		$num2=pdo_count('jy_cmsactivity_order',array('uniacid'=>$_SESSION['uniacid'],'activity_id'=>$item['id'],'status'=>2));
		$num3=pdo_count('jy_cmsactivity_order',array('uniacid'=>$_SESSION['uniacid'],'activity_id'=>$item['id'],'status'=>4));
		$item['num']=$num1+$num2+$num3;
		if($item['mannum']-$item['num'] >= 0){
			$item['left']=$item['mannum']-$item['num'];
		}else{
			$item['left']=0;
		}
	}
	$return['post']=array();
	$return['list']=$list;
	$return['show_list']=$show_list;
	exi($return);
}
if($_RQ['op']=='detail'){
	if(!$_RQ['id']){
		exi('没有找到该活动，请重新选择！','error','jy_cmsactivity/list/list');
	}
	pdo_update('jy_cmsactivity_list',array('readnum +'=>1,),array('uniacid'=>$_SESSION['uniacid'],'id'=>$_RQ['id']));
	$activity=pdo_get('jy_cmsactivity_list',array('uniacid'=>$_SESSION['uniacid'],'id'=>$_RQ['id']));
	$num1=pdo_count('jy_cmsactivity_order',array('uniacid'=>$_SESSION['uniacid'],'activity_id'=>$activity['id'],'status'=>1));
	$num2=pdo_count('jy_cmsactivity_order',array('uniacid'=>$_SESSION['uniacid'],'activity_id'=>$activity['id'],'status'=>2));
	$num3=pdo_count('jy_cmsactivity_order',array('uniacid'=>$_SESSION['uniacid'],'activity_id'=>$activity['id'],'status'=>4));
	$activity['num']=$num1+$num2+$num3;
	$this->session('activity_id',$_RQ['id']);
	$return['activity']=$activity;
	$return['banner']=json_decode($activity['hdp'],true);
	$return['sharedata'] = array(
		'title'=>$return['activity']['title'],
		'desc'=>$return['activity']['remark'],
		'imgUrl'=>tomedia($activity['image']),
	);
	$return['post']=array();
	exi($return);
}
if($_RQ['op']=='notice'){
	
	$postdata=get_postdata();
	$activity_id = $this->session('activity_id');
	$activity=pdo_get('jy_cmsactivity_list',array('uniacid'=>$_SESSION['uniacid'],'id'=>$activity_id));
	
	if($postdata){

			$insert=array(
				'uniacid'=>$_SESSION['uniacid'],
				'user_id'=>$_SESSION['uid'],
				'activity_id'=>$this->session('activity_id'),
				'money'=>$activity['money'],
			//	'ordersn'=>get_ordersn('jy_cmsactivity_order','ordersn'),
				'createtime'=>TIMESTAMP,
			);
		//	exi($insert,'error');
			pdo_insert('jy_cmsactivity_order',$insert);
			$id=pdo_insertid();
	}
	$update=array();
	if($postdata['name']){
		$update['realname']=$postdata['name'];
	}
	if($postdata['mobile']){
		$update['mobile']=$postdata['mobile'];
	}
	if($postdata['name'] || $postdata['mpbile']){
		pdo_update('core_members',$update,array('id'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']));
	}
	//exi('提交订单');
	exi('','','jy_cmsactivity/book/main/id='.$id);
}